package com.highspeed.bdk.controller.deploy;

import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.highspeed.bdk.bean.entity.deploy.AppCpuBindor;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.base.IBdkBaseService;
import com.highspeed.bdk.service.physical.IAppCpuBindorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping(value = "app_cpu_bindor", method = RequestMethod.POST)
@Api(tags = "APP_CPU绑定")
public class AppCpuBindorController extends BdkCrudController<AppCpuBindor, Integer> {

    @Autowired
    private IAppCpuBindorService appCpuBindorService;

    @Override
    protected IBdkBaseService<AppCpuBindor, Integer> getService() {
        return appCpuBindorService;
    }

    @JSON(excludeProperties = {"data.*\\.logicTopology", "data.*\\.preinstalledRedLogicTopology", "data.*\\.board", "data.*\\.rightLinks", "data.*\\.leftLinks"})
    @ApiOperation(value = "根据板卡ID查询内部所有CPU与App绑定信息", notes = "1个板卡上最多4个CPU，每个CPU上只能绑1个APP")
    @ApiImplicitParam(name = "id", value = "板卡id", dataType = "int", paramType = "query")
    @RequestMapping(value = {"/query_bindor_by_boardid"}, method = RequestMethod.POST)
    public Page<AppCpuBindor> queryBindorByBoardId(Integer id) {
        LinkedHashMap params = new LinkedHashMap();
        params.put("cpu.board.id_eq", id);
        return appCpuBindorService.query(params, null);
    }

    @JSON(excludeProperties = {"data.*\\.logicTopology", "data.*\\.preinstalledRedLogicTopology", "data.*\\.board", "data.*\\.rightLinks", "data.*\\.leftLinks"})
    @ApiOperation(value = "根据板卡真实的ID查询内部所有CPU与App绑定信息", notes = "1个板卡上最多4个CPU，每个CPU上只能绑1个APP")
    @ApiImplicitParam(name = "id", value = "真实的板卡id，也就是网关初始化返回的id", dataType = "int", paramType = "query")
    @RequestMapping(value = {"/query_bindor_by_deviceId"}, method = RequestMethod.POST)
    public Page<AppCpuBindor> queryBindorByDeviceId(Integer id) {
        LinkedHashMap params = new LinkedHashMap();
        params.put("cpu.board.boardId_eq", id);
        return appCpuBindorService.query(params, null);
    }
}
